﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CodeBuilder2.BLL;
using System.Data;
using CodeBuilder2.BLL.CodeGenerateor;
using System.CodeDom.Compiler;
using System.CodeDom;

namespace CodeBuilder2
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

        }
        
        BuilderBaiscServices s = new BuilderBaiscServices();
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            DataTable dt = s.GetLibrarysName();
            //string[] str = { "d", "e" };
            //var t = from ss in str
            //        select e;
            foreach (DataRow dr in dt.Rows)
            {
                tbk.Text += dr[0];
            }
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            BuilderBaiscServices bbsBll = new BuilderBaiscServices();
            DataSet ds = bbsBll.GetColumns("xy_order");
            EntityGenerator eg = new EntityGenerator();
            eg.ClassName = ds.Tables[0].Rows[0]["table_name"].ToString();
            eg.FieldTableInfo = ds.Tables[0];
            eg.NameSpace = "XYProduct.Model";
            CodeDomProvider cdp;
            switch (((ComboBoxItem)this.comboBox1.SelectedItem).Content.ToString())
            {
                case "CSharp":
                    cdp = CodeDomProvider.CreateProvider("CSharp");
                    break;
                case "Visual Basic":
                    cdp = CodeDomProvider.CreateProvider("VisualBasic");
                    break;
                case "JScript":
                    cdp = CodeDomProvider.CreateProvider("JScript");
                    break;
                default:
                    cdp = CodeDomProvider.CreateProvider("CSharp");
                    break;
            }
            textBox1.Text = eg.GenerateCode(cdp);
        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            canvas1.Width = 3000;
        }
    }
}
